﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/MasterPage.master" AutoEventWireup="true" CodeFile="Transportes.aspx.cs" Inherits="Companies_Transportes" Title="Транспортни Фирми" %>

<%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <p>
        &nbsp;</p>
    <p>
        СПИСЪК НА ТРАНСПОРТНИТЕ ФИРМИ</p>
    <telerik:RadGrid ID="rgTransporters" runat="server" 
        AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" AllowPaging="True" 
        DataSourceID="sdsTransport" GridLines="None" Width="0px">
        <HeaderContextMenu EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </HeaderContextMenu>
        <MasterTableView DataSourceID="sdsTransport" DataKeyNames="TransporterID" 
            AutoGenerateColumns="false" 
            EditFormSettings-EditColumn-ButtonType="ImageButton" 
            EditFormSettings-EditColumn-CancelText="Прекрати" 
            EditFormSettings-EditColumn-UpdateText="Обнови" EditFormSettings-EditColumn-InsertText="Въведи"
            EditMode="EditForms" AllowPaging="true" 
            PagerStyle-Mode="NextPrevAndNumeric" CommandItemDisplay="Top" 
            CommandItemSettings-RefreshText="Обнови" 
            CommandItemSettings-AddNewRecordText="Добави нов запис">
<CommandItemSettings AddNewRecordText="Добави нов запис" RefreshText="Обнови"></CommandItemSettings>

            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridBoundColumn UniqueName="TransporterID" HeaderText="TransporterID" 
                    DataField="TransporterID" DataType="System.Int32" ReadOnly="True" 
                    SortExpression="TransporterID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="Name" HeaderText="Name" DataField="Name" 
                    DataType="System.String" SortExpression="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn UniqueName="AddressCorrespondence" 
                    HeaderText="AddressCorrespondence" DataField="AddressCorrespondence" 
                    DataType="System.String" SortExpression="AddressCorrespondence">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AddressInvoice" HeaderText="AddressInvoice" 
                    SortExpression="AddressInvoice" UniqueName="AddressInvoice">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IDNUM" HeaderText="IDNUM" 
                    SortExpression="IDNUM" UniqueName="IDNUM">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="VATNO" HeaderText="VATNO" 
                    SortExpression="VATNO" UniqueName="VATNO">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="MRP" HeaderText="MRP" SortExpression="MRP" 
                    UniqueName="MRP">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Phone" HeaderText="Phone" 
                    SortExpression="Phone" UniqueName="Phone">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Fax" HeaderText="Fax" SortExpression="Fax" 
                    UniqueName="Fax">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Website" HeaderText="Website" 
                    SortExpression="Website" UniqueName="Website">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Bank" HeaderText="Bank" 
                    SortExpression="Bank" UniqueName="Bank">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="BankAddress" HeaderText="BankAddress" 
                    SortExpression="BankAddress" UniqueName="BankAddress">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="AccountNo" HeaderText="AccountNo" 
                    SortExpression="AccountNo" UniqueName="AccountNo">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="BIC" HeaderText="BIC" SortExpression="BIC" 
                    UniqueName="BIC">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="IBAN" HeaderText="IBAN" 
                    SortExpression="IBAN" UniqueName="IBAN">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="BankGiro" HeaderText="BankGiro" 
                    SortExpression="BankGiro" UniqueName="BankGiro">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="PostGiro" HeaderText="PostGiro" 
                    SortExpression="PostGiro" UniqueName="PostGiro">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="CountryID" DataType="System.Int32" 
                    HeaderText="CountryID" SortExpression="CountryID" UniqueName="CountryID">
                </telerik:GridBoundColumn>
   <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" Text="Изтрий"
                            HeaderText="Изтрий" UniqueName="columnDelete" ConfirmText="Сигурни ли сте, че искате да изтриете записа?"
                            ItemStyle-Width="10%">
                            <ItemStyle Width="10%"></ItemStyle>
                        </telerik:GridButtonColumn>
            </Columns>

<EditFormSettings>
<EditColumn ButtonType="ImageButton" CancelText="Прекрати" UpdateText="Обнови" InsertText="Въведи"></EditColumn>
</EditFormSettings>

<PagerStyle Mode="NextPrevAndNumeric"></PagerStyle>
        </MasterTableView>
        <FilterMenu EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </FilterMenu>
    </telerik:RadGrid>
        <asp:SqlDataSource ID="sdsTransport" runat="server" 
        ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
        DeleteCommand="DELETE FROM [Transporters] WHERE [TransporterID] = @TransporterID" 
        InsertCommand="INSERT INTO [Transporters] ([Name], [AddressCorrespondence], [AddressInvoice], [IDNUM], [VATNO], [MRP], [Phone], [Fax], [Website], [Bank], [BankAddress], [AccountNo], [BIC], [IBAN], [BankGiro], [PostGiro], [CountryID]) VALUES (@Name, @AddressCorrespondence, @AddressInvoice, @IDNUM, @VATNO, @MRP, @Phone, @Fax, @Website, @Bank, @BankAddress, @AccountNo, @BIC, @IBAN, @BankGiro, @PostGiro, @CountryID)" 
        SelectCommand="SELECT * FROM [Transporters]" 
        UpdateCommand="UPDATE [Transporters] SET [Name] = @Name, [AddressCorrespondence] = @AddressCorrespondence, [AddressInvoice] = @AddressInvoice, [IDNUM] = @IDNUM, [VATNO] = @VATNO, [MRP] = @MRP, [Phone] = @Phone, [Fax] = @Fax, [Website] = @Website, [Bank] = @Bank, [BankAddress] = @BankAddress, [AccountNo] = @AccountNo, [BIC] = @BIC, [IBAN] = @IBAN, [BankGiro] = @BankGiro, [PostGiro] = @PostGiro, [CountryID] = @CountryID WHERE [TransporterID] = @TransporterID">
            <DeleteParameters>
                <asp:Parameter Name="TransporterID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:Parameter Name="CountryID" Type="Int32" />
                <asp:Parameter Name="TransporterID" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:Parameter Name="CountryID" Type="Int32" />
            </InsertParameters>
    </asp:SqlDataSource>
    <br />
        <asp:GridView ID="gvTransporters" runat="server" AutoGenerateColumns="False" 
            DataKeyNames="TransporterID" DataSourceID="sdsTransporters" 
            onselectedindexchanged="gvTransporters_SelectedIndexChanged" 
            BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" 
            CellPadding="4" ForeColor="Black" GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <Columns>
                <asp:CommandField SelectText="Избери" ShowSelectButton="True" />
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идент. № по ЗДДС/VATNO" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ" 
                    SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="NameBG" HeaderText="Държава" 
                    SortExpression="NameBG" />
                <asp:TemplateField HeaderText="Продукти">
                    <ItemTemplate>
                      <a href='TransportTables.aspx?TransporterID=<%# Eval("TransporterID") %>'>Транспортна Таблица</a> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:GridView>
        <asp:Button ID="btnNewTransporter" runat="server" 
            Text="Съдай нова транспортна фирма" onclick="btnNewTransporter_Click" />
    </p>
    <p>
        <asp:DetailsView ID="dvTransporters" runat="server" AutoGenerateRows="False" 
            DataKeyNames="TransporterID" DataSourceID="sdsTransportersDetails" 
            Height="50px" Width="125px" AllowPaging="True" 
            onitemdeleted="dvTransporterDetails_ItemDeleted" 
            oniteminserted="dvTransporterDetails_ItemInserted" 
            onitemupdated="dvTransporterDetails_ItemUpdated" BackColor="White" 
            BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" 
            ForeColor="Black" GridLines="Vertical">
            <FooterStyle BackColor="#CCCC99" />
            <RowStyle BackColor="#F7F7DE" />
            <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
            <Fields>
                <asp:BoundField DataField="Name" HeaderText="Име" SortExpression="Name" />
                <asp:BoundField DataField="AddressInvoice" HeaderText="Адрес за фактури" 
                    SortExpression="AddressInvoice" />
                <asp:BoundField DataField="AddressCorrespondence" 
                    HeaderText="Адрес за кореспонденция" SortExpression="AddressCorrespondence" />
                <asp:BoundField DataField="IDNUM" HeaderText="Идент. №" 
                    SortExpression="IDNUM" />
                <asp:BoundField DataField="VATNO" HeaderText="Идентификационен № по ЗДДС/VAT" 
                    SortExpression="VATNO" />
                <asp:BoundField DataField="MRP" HeaderText="МОЛ:" SortExpression="MRP" />
                <asp:BoundField DataField="Phone" HeaderText="Телефон" SortExpression="Phone" />
                <asp:BoundField DataField="Fax" HeaderText="Факс" SortExpression="Fax" />
                <asp:BoundField DataField="Website" HeaderText="Уебсайт" SortExpression="Website" />
                <asp:BoundField DataField="Bank" HeaderText="Банка" SortExpression="Bank" />
                <asp:BoundField DataField="BankAddress" HeaderText="Адрес на банката" 
                    SortExpression="BankAddress" />
                <asp:BoundField DataField="AccountNo" HeaderText="Сметка №" SortExpression="AccountNo" />
                <asp:BoundField DataField="IBAN" HeaderText="IBAN" SortExpression="IBAN" />
                <asp:BoundField DataField="BIC" HeaderText="BIC" SortExpression="BIC" />
                <asp:BoundField DataField="BankGiro" HeaderText="BankGiro" SortExpression="BankGiro" />
                <asp:BoundField DataField="PostGiro" HeaderText="PostGiro" SortExpression="PostGiro" />
                <asp:TemplateField HeaderText="Държава" SortExpression="NameBG">
                    <EditItemTemplate>
                        <asp:DropDownList ID="ddlCountries" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </EditItemTemplate>
                    <InsertItemTemplate>
                        <asp:DropDownList ID="ddlCountriesIns" runat="server" DataSourceID="sdsCountries" DataTextField="NameBG" DataValueField="CountryID">
                        </asp:DropDownList>
                    </InsertItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="Label1" runat="server" Text='<%# Bind("NameBG") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                    ShowInsertButton="True" CancelText="Прекъсни" DeleteText="Изтриване" 
                    EditText="Редактиране" InsertText="Вмъкване" NewText="Нов" SelectText="Избери" 
                    UpdateText="Обнови" />
            </Fields>
            <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
        </asp:DetailsView>
        <asp:SqlDataSource ID="sdsTransporters" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            SelectCommand="SELECT Transporters.TransporterID, Transporters.IDNUM, Transporters.Name, Transporters.VATNO, Transporters.MRP, Transporters.Phone, Transporters.Fax, Countries.NameBG FROM Transporters INNER JOIN Countries ON Transporters.CountryID = Countries.CountryID">
        </asp:SqlDataSource>
        
        <asp:SqlDataSource ID="sdsCountries" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            
            SelectCommand="SELECT [CountryID], [NameBG] FROM [Countries] ORDER BY NameBG">
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="sdsTransportersDetails" runat="server" 
            ConnectionString="<%$ ConnectionStrings:KonturConnectionString %>" 
            DeleteCommand="DELETE FROM [Transporters] WHERE [TransporterID] = @TransporterID" 
            InsertCommand="INSERT INTO [Transporters] ([Name], [AddressCorrespondence], [AddressInvoice], [IDNUM], [VATNO], [MRP], [Phone], [Fax], [Website], [Bank], [BankAddress], [AccountNo], [BIC], [IBAN], [BankGiro], [PostGiro], [CountryID]) VALUES (@Name, @AddressCorrespondence, @AddressInvoice, @IDNUM, @VATNO, @MRP, @Phone, @Fax, @Website, @Bank, @BankAddress, @AccountNo, @BIC, @IBAN, @BankGiro, @PostGiro, @CountryID)" 
            SelectCommand="SELECT Transporters.TransporterID, Transporters.Name, Transporters.AddressCorrespondence, Transporters.AddressInvoice, Transporters.IDNUM, Transporters.VATNO, Transporters.MRP, Transporters.Phone, Transporters.Fax, Transporters.Website, Transporters.Bank, Transporters.BankAddress, Transporters.AccountNo, Transporters.BIC, Transporters.IBAN, Transporters.BankGiro, Transporters.PostGiro, Countries.NameBG FROM Transporters INNER JOIN Countries ON Transporters.CountryID = Countries.CountryID WHERE (Transporters.TransporterID = @TransporterID)" 
            UpdateCommand="UPDATE [Transporters] SET [Name] = @Name, [AddressCorrespondence] = @AddressCorrespondence, [AddressInvoice] = @AddressInvoice, [IDNUM] = @IDNUM, [VATNO] = @VATNO, [MRP] = @MRP, [Phone] = @Phone, [Fax] = @Fax, [Website] = @Website, [Bank] = @Bank, [BankAddress] = @BankAddress, [AccountNo] = @AccountNo, [BIC] = @BIC, [IBAN] = @IBAN, [BankGiro] = @BankGiro, [PostGiro] = @PostGiro, [CountryID] = @CountryID WHERE [TransporterID] = @TransporterID">
            <SelectParameters>
                <asp:ControlParameter ControlID="gvTransporters" PropertyName="SelectedValue" Name="TransporterID" Type="Int32" />
           </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="TransporterID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvTransporters$ddlCountries" PropertyName="SelectedValue" />
                <asp:Parameter Name="TransporterID" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="AddressCorrespondence" Type="String" />
                <asp:Parameter Name="AddressInvoice" Type="String" />
                <asp:Parameter Name="IDNUM" Type="String" />
                <asp:Parameter Name="VATNO" Type="String" />
                <asp:Parameter Name="MRP" Type="String" />
                <asp:Parameter Name="Phone" Type="String" />
                <asp:Parameter Name="Fax" Type="String" />
                <asp:Parameter Name="Website" Type="String" />
                <asp:Parameter Name="Bank" Type="String" />
                <asp:Parameter Name="BankAddress" Type="String" />
                <asp:Parameter Name="AccountNo" Type="String" />
                <asp:Parameter Name="BIC" Type="String" />
                <asp:Parameter Name="IBAN" Type="String" />
                <asp:Parameter Name="BankGiro" Type="String" />
                <asp:Parameter Name="PostGiro" Type="String" />
                <asp:ControlParameter Name="CountryID" Type="Int32" ControlID="ctl00$ContentPlaceHolder1$dvTransporters$ddlCountriesIns" PropertyName="SelectedValue" />
            </InsertParameters>
        </asp:SqlDataSource></p>
</asp:Content>

